//
//  DDNotificationMessageCell.m
//  DingDongZP
//
//  Created by 王威 on 16/3/18.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDNotificationMessageCell.h"
#import "NSDate+DateDisplayString.h"
#import "DDJobfinderNotification.h"
#import "DDAPIGenerate.h"
#import "DDEmployerNotification.h"

@interface DDNotificationMessageCell ()

@property (strong, nonatomic) UIImageView   *userImageView;
@property (strong, nonatomic) UILabel       *companyLabel;
@property (strong, nonatomic) UILabel       *recruitInfoLabel;
@property (strong, nonatomic) UILabel       *postInfoLabel;
@property (strong, nonatomic) UILabel       *timeLabel;
@property (strong, nonatomic) UIImageView   *styleImageView;

@end

@implementation DDNotificationMessageCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.userImageView = [[UIImageView alloc] init];
        self.userImageView.layer.masksToBounds = YES;
        self.userImageView.layer.cornerRadius = 25.f;
        [self.contentView addSubview:_userImageView];
        
        self.companyLabel = [[UILabel alloc] init];
        self.companyLabel.textAlignment = NSTextAlignmentLeft;
        self.companyLabel.textColor = COLOR_FONT_MAIN_GREEN;
        self.companyLabel.font = [UIFont systemFontOfSize:13.f];
        [self.contentView addSubview:_companyLabel];
        
        self.recruitInfoLabel = [[UILabel alloc] init];
        self.recruitInfoLabel.textAlignment = NSTextAlignmentLeft;
        self.recruitInfoLabel.textColor = COLOR_FONT_DARK_GRAY;
        self.recruitInfoLabel.font = [UIFont systemFontOfSize:13.f];
        [self.contentView addSubview:_recruitInfoLabel];
        
        self.postInfoLabel = [[UILabel alloc] init];
        self.postInfoLabel.textAlignment = NSTextAlignmentLeft;
        self.postInfoLabel.textColor = COLOR_FONT_DARK_GRAY;
        self.postInfoLabel.font = [UIFont systemFontOfSize:13.f];
        [self.contentView addSubview:_postInfoLabel];
        
        self.timeLabel = [[UILabel alloc] init];
        self.timeLabel.textAlignment = NSTextAlignmentRight;
        self.timeLabel.textColor = COLOR_FONT_LIGHT_GRAY;
        self.timeLabel.font = [UIFont systemFontOfSize:13.f];
        [self.contentView addSubview:_timeLabel];
        
        self.styleImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_styleImageView];
        
        [self setViewContraints];
        
        // test data
        [self.userImageView sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"message_icon_defualt"]];
        self.companyLabel.text = @"八仙广告 常彩虹";
        self.recruitInfoLabel.text = @"15-17k | 杭州 | 1-3年 | 本科";
        self.postInfoLabel.text = @"对您的简历感兴趣";
        self.timeLabel.text = [NSDate dateToDisplayStringForDateString:@"2016-02-17 18:33"];
        self.styleImageView.image = [UIImage imageNamed:@"notification_check"];
    }
    return self;
}

- (void)setViewContraints
{
    
    
    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@14.5);
        make.top.mas_equalTo(@13.f);
        make.size.mas_equalTo(CGSizeMake(50.f, 50.f));
    }];
    
    [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.userImageView.mas_right).and.offset(10.f);
        make.top.equalTo(self.userImageView);
        make.width.equalTo(self).and.offset(-180);
        make.height.mas_equalTo(@18.f);
    }];
    
    [self.recruitInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.companyLabel.mas_bottom).and.offset(2.f);
        make.left.equalTo(self.companyLabel);
        make.width.equalTo(self.companyLabel);
        make.height.equalTo(self.companyLabel);
    }];
    
    [self.postInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.recruitInfoLabel.mas_bottom).and.offset(2.f);
        make.left.equalTo(self.recruitInfoLabel);
        make.width.equalTo(self.recruitInfoLabel);
        make.height.equalTo(self.recruitInfoLabel);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).and.offset(-10);
        make.top.equalTo(self.companyLabel);
        make.width.mas_equalTo(@100);
        make.height.equalTo(self.companyLabel);
    }];
    
    [self.styleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.timeLabel);
        make.top.equalTo(self.timeLabel.mas_bottom).and.offset(12);
        make.size.mas_equalTo(CGSizeMake(25.f, 25.f));
    }];

//    ESWeakSelf
//    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        ESStrongSelf
//        make.left.mas_equalTo(@14.5);
//        make.top.mas_equalTo(@13.f);
//        make.size.mas_equalTo(CGSizeMake(50.f, 50.f));
//    }];
//    
//    [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        ESStrongSelf
//        make.left.equalTo(_self.userImageView.mas_right).and.offset(10.f);
//        make.top.equalTo(_self.userImageView);
//        make.width.equalTo(_self).and.offset(-180);
//        make.height.mas_equalTo(@18.f);
//    }];
//    
//    [self.recruitInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        ESStrongSelf
//        make.top.equalTo(_self.companyLabel.mas_bottom).and.offset(2.f);
//        make.left.equalTo(_self.companyLabel);
//        make.width.equalTo(_self.companyLabel);
//        make.height.equalTo(_self.companyLabel);
//    }];
//    
//    [self.postInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        ESStrongSelf
//        make.top.equalTo(_self.recruitInfoLabel.mas_bottom).and.offset(2.f);
//        make.left.equalTo(_self.recruitInfoLabel);
//        make.width.equalTo(_self.recruitInfoLabel);
//        make.height.equalTo(_self.recruitInfoLabel);
//    }];
//    
//    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        ESStrongSelf;
//        make.right.equalTo(_self).and.offset(-10);
//        make.top.equalTo(_self.companyLabel);
//        make.width.mas_equalTo(@100);
//        make.height.equalTo(_self.companyLabel);
//    }];
//    
//    [self.styleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        ESStrongSelf;
//        make.right.equalTo(_self.timeLabel);
//        make.top.equalTo(_self.timeLabel.mas_bottom).and.offset(12);
//        make.size.mas_equalTo(CGSizeMake(25.f, 25.f));
//    }];
}

- (void)setModel:(id)model
{
    if ([model isKindOfClass:[DDJobfinderNotification class]])
    {
        DDJobfinderNotification *notification = (DDJobfinderNotification *)model;
        
        NSString *url = [DDAPIGenerate imageURLWithPath:notification.logo];
        [self.userImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"message_icon_defualt"]];
        
        NSString *title = [NSString stringWithFormat:@"%@ %@", !notification.companyshortname?@"职位未填写":notification.companyshortname, !notification.name?@"姓名未填写":notification.name];
        self.companyLabel.text = title;
        NSString *info = [NSString stringWithFormat:@"%@ | %@ | %@ | %@",!notification.salary?@"薪资":notification.salary, !notification.city?@"城市":notification.city, !notification.experience?@"经验":notification.experience, !notification.edu?@"学历":notification.edu];
        self.recruitInfoLabel.text = info;
        NSString *action = nil;
        switch (notification.type) {
            case DDJobfinderNotificationBeLooked: {
                action = @"查看了您的简历";
                self.styleImageView.image = [UIImage imageNamed:@"notification_check"];
                break;
            }
            case DDJobfinderNotificationBeInterested: {
                action = @"对您的简历感兴趣";
                self.styleImageView.image = [UIImage imageNamed:@"notification_interest"];
                break;
            }
            case DDJobfinderNotificationNewJobs: {
                action = [NSString stringWithFormat:@"发布了%@",!notification.jobtitle?@"新职位":notification.jobtitle];
                self.styleImageView.image = [UIImage imageNamed:@"notification_new"];
                break;
            }
            default:
                break;
        }
        self.postInfoLabel.text = action;
        self.timeLabel.text = notification.time;

    } else if ([model isKindOfClass:[DDEmployerNotification class]]) {
        
        DDEmployerNotification *notification = (DDEmployerNotification *)model;
        
        NSString *url = [DDAPIGenerate imageURLWithPath:notification.logo];
        [self.userImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"message_icon_defualt"]];
        
        NSString *title = [NSString stringWithFormat:@"%@ %@", !notification.category?@"职位未填写":notification.category, !notification.name?@"姓名未填写":notification.name];
        
        self.companyLabel.text = title;
        NSString *info = [NSString stringWithFormat:@"%@ | %@ | %@ | %@",!notification.salary?@"薪资":notification.salary, !notification.city?@"城市":notification.city, !notification.experience?@"经验":notification.experience, !notification.edu?@"学历":notification.edu];
        self.recruitInfoLabel.text = info;
        NSString *action = nil;
        switch (notification.type) {
            case DDEmployerNotificationJobViewed: {
                action = @"查看了您的职位";
                self.styleImageView.image = [UIImage imageNamed:@"notification_check"];
                break;
            }
            case DDEmployerNotificationInterested: {
                action = @"对您的职位感兴趣";
                self.styleImageView.image = [UIImage imageNamed:@"notification_interest"];
                break;
            }
            case DDEmployerNotificationNewFinder: {
                action = [NSString stringWithFormat:@"刚刚加入"];
                self.styleImageView.image = [UIImage imageNamed:@"notification_new"];
                break;
            }
            default:
                break;
        }
        self.postInfoLabel.text = action;
        self.timeLabel.text = notification.time;
    }
}

@end
